﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using GenericLibrariesToolKit;
using GenericLibrariesToolKit.Enumeration;
using Model;
using BLL.Users;
using BLL.Users.Impl;
using Utils;

public partial class Page_Security_RegisterCheckDetails : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack && Request.QueryString["userID"] != null)
        {
            string userID = Request.QueryString["userID"].ToString();
            if (Request.QueryString["userType"] == "Expert")
                    showExpertRegisterCheckDetail(userID);
            if (Request.QueryString["userType"] == "Enterprise")
                showEnterpriseRegisterCheckDetail(userID);
        }
    }

    /// <summary>
    /// 显示专家注册用户详细信息
    /// </summary>
    /// <param name="userID">专家用户ID</param>
    public void showExpertRegisterCheckDetail(string userID)
    {
        ExpertBO expertBO = new ExpertBOImpl();
        //设置where查询条件
        WhereCondition[] whereCondition = new WhereCondition[]
        {
            new WhereCondition(WhereJoinType.NULL,"ExpertId",MatchType.EQUAL,userID),
        };
        //执行语句
        DataSet resultExpert = expertBO.GetDataSet(-1,-1,whereCondition); 
        //绑定数据
        gvExpertRegisterCheckDetails.DataSource = resultExpert;
        gvExpertRegisterCheckDetails.DataBind();
    }

    /// <summary>
    /// 显示企业注册用户详细信息
    /// </summary>
    /// <param name="userID">企业用户ID</param>
    public void showEnterpriseRegisterCheckDetail(string userID)
    {
        EnterpriseBO enterpriseBO = new EnterpriseBOImpl();
        //设置where查询条件
        WhereCondition[] whereCondition = new WhereCondition[]
        {
            new WhereCondition(WhereJoinType.NULL,"EnterpriseId",MatchType.EQUAL,userID),
        };
        //执行语句
        DataSet resultEnterprise = enterpriseBO.GetDataSet(-1, -1, whereCondition);
        //绑定数据
        gvEnterpriseRegisterCheckDetails.DataSource = resultEnterprise;
        gvEnterpriseRegisterCheckDetails.DataBind();
    }

    /// <summary>
    /// 返回上一页面
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnRegisterDetailsBack_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("RegisterCheckList.aspx");
    }

    /// <summary>
    /// 使当前注册用户通过审核
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnRegisterDetailsPass_Click(object sender, ImageClickEventArgs e)
    {
        string userID = Request.QueryString["userID"].ToString();
        User user=new User
        {
            IsAuditing=1,
            UserId=userID,
        };

        UserBO userBO = new UserBOImpl();
        bool result = userBO.Update(user);
        if(result)
            Response.Write("<script>alert('" + "Passed" + "')</script>");
        Response.Redirect("RegisterCheckList.aspx");
    }

    /// <summary>
    /// 拒绝当前用户注册
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnRegisterDetailsReject_Click(object sender, ImageClickEventArgs e)
    {
        string userID = Request.QueryString["userID"].ToString();
        UserBO userBO = new UserBOImpl();
        bool result = userBO.Delete(userID);
        if(result)
            Response.Write("<script>alert('" + "Reject" + "')</script>");
        Response.Redirect("RegisterCheckList.aspx");
    }
}